{include file="head_2" title="设备列表" /}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <from class="layui-form">
                <div class="demoTable">
                    &nbsp;&nbsp;名称:
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" style="width: 280px;" class="layui-input" id="name" value="" placeholder="" lay-key="17">
                        </div>
                    </div>
                    &nbsp;&nbsp;状态:
                    <div class="layui-inline">

                        <select name="status" lay-filter="status" id="status" lay-verify="required">
                            <option value=""></option>
                        </select>
                    </div>
                    &nbsp;&nbsp;&nbsp;添加时间：
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" style="width: 280px;" class="layui-input" id="Sapplydate" value="" placeholder="" lay-key="17">
                        </div>
                    </div>
                    <button class="layui-btn" data-type="reload">搜索</button>
                    <!--<a class="layui-btn layui-btn-primary" href="/admin/{$controller}/add">添加</a>-->
                </div>
            </from>
            <div style="clear:both"></div>
            <table class="layui-table" lay-data="{ url:'/admin/{$controller}/get_list/?key[user_id]={$my_self['id']==1?0:$my_self['id']}', page:true, id:'idTest'}" lay-filter="demo">
                <thead>
                <tr>
                    <th lay-data="{field:'uniqueid',align:'center',  width:200}">编号</th>
                    <th lay-data="{field:'tel',align:'left', width:200}">电话</th>
                    <th lay-data="{field:'user_name', align:'left', width:200}">宝宝</th>
                    <th lay-data="{field:'create_at', align:'left', width:200}">添加时间</th>
                    <th lay-data="{field:'last_time',align:'center', width:100}">最后登陆</th>
                    <th lay-data="{fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}">操作</th>
                </tr>
                </thead>
            </table>

        </div>
    </div>
</div>

<script type="text/html" id="barDemo">
    <!--<a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>-->
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
    layui.use(['layer', 'table','laydate', 'jquery'], function () {
        var layer = layui.layer //弹层
            , table = layui.table //表格
            , laydate = layui.laydate
            , $ = layui.$;


        laydate.render({
            elem: '#Sapplydate'
            , type: 'datetime'
            , range: '--'
            , format: 'yyyy-M-d H:m:s'
        });

        var active = {
            reload: function () {
                table.reload('idTest', {
                    where: {
                        key: {
                            date: $('#Sapplydate').val(),
                            name: $('#name').val(),
                            status: $('#status').val(),
                        }
                    }
                });
            }
        };
        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data
                , layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    del_data(obj);
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if (layEvent === 'edit') {
                location.href = "/admin/{$controller}/edit/id/" + data.id;
            } else if (layEvent === 'frozen') {
                layer.confirm('真的冻结么', function (index) {
                    frozen_data(obj);
                    layer.close(index);
                });
            }
        });
        function del_data(obj)
        {
            var data = obj.data;
            $.ajax({
                url: "/admin/{$controller}/del_submit/",
                type: 'post',
                data: {id: data.id},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1)
                    {
                        layer.msg("删除成功!", {
                            time: 1000
                        }, function () {
                            location.reload();
                        });
                    } else
                    {
                        layer.msg(data.msg);
                    }
                },
            });
        }
        function frozen_data(obj)
        {
            var data = obj.data;
            $.ajax({
                url: "/admin/{$controller}/contents_submit/",
                type: 'post',
                data: {id: data.id,status:3},
                dataType: 'json',
                success: function (data) {
                    if (data.status == 1)
                    {
                        layer.msg("冻结成功!", {
                            time: 1000
                        }, function () {
                            location.reload();
                        });
                    } else
                    {
                        layer.msg(data.msg);
                    }
                },
            });
        }
    });
</script>
{include file="foot" /}